package com.example.administrator.hqq.activity.post;

import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.util.Util;
import com.example.administrator.hqq.R;
import com.example.administrator.hqq.View.alertview.AlertViewFactory;
import com.example.administrator.hqq.adapter.discover.CommentDetailsAdapter;
import com.example.administrator.hqq.base.MyActivity;
import com.example.administrator.hqq.bean.ForumComment;
import com.example.administrator.hqq.bean.post.CommentDetailsBean;
import com.example.administrator.hqq.config.LoongsConfig;
import com.example.administrator.hqq.config.UrlFactory;
import com.example.administrator.hqq.message.PostDetailsMessageEvent;
import com.example.administrator.hqq.utils.HintWordsUtils;
import com.example.administrator.hqq.utils.MyTextUtils;
import com.example.administrator.hqq.utils.TimeUtils;
import com.example.administrator.hqq.utils.transform.GlideCircleTransform;
import com.google.gson.Gson;
import com.scwang.smartrefresh.header.MaterialHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.builder.GetBuilder;
import com.zhy.http.okhttp.callback.StringCallback;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

public class CommentDetailsActivity extends MyActivity {

    @BindView(R.id.return_auto)
    AutoRelativeLayout returnAuto;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.report_auto)
    AutoRelativeLayout reportAuto;
    @BindView(R.id.comment_et)
    EditText commentEt;
    @BindView(R.id.issue1)
    AutoLinearLayout issue;
    @BindView(R.id.auto)
    AutoLinearLayout auto;
    @BindView(R.id.user_pic)
    ImageView userPic;
    @BindView(R.id.user_name)
    TextView userName;
    @BindView(R.id.comment_context)
    TextView commentContext;
    @BindView(R.id.inform)
    AutoRelativeLayout inform;
    @BindView(R.id.comment_time)
    TextView commentTime;
    @BindView(R.id.comment_give_like)
    ImageView commentGiveLike;
    @BindView(R.id.post_disagree)
    ImageView postDisagree;
    @BindView(R.id.auto2)
    AutoLinearLayout auto2;
    @BindView(R.id.view1)
    View view1;
    @BindView(R.id.reply_number)
    TextView replyNumber;
    @BindView(R.id.recycler)
    RecyclerView recycler;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
    @BindView(R.id.like_number)
    TextView likeNumber;
    @BindView(R.id.like_auto)
    AutoLinearLayout likeAuto;
    @BindView(R.id.auto_gray)
    AutoLinearLayout autoGray;
    @BindView(R.id.scrollView)
    ScrollView scrollView;
    @BindView(R.id.examine_forum)
    TextView examineForum;
    private List<CommentDetailsBean.DataBean.DiscussionBean> data;
    private String last_id;
    private int page = 1;
    private String TAG = this.getClass().getSimpleName();
    private CommentDetailsAdapter commentDetailsAdapter;
    private CommentDetailsBean commentDetailsBean;
    private boolean aBoolean = true;//true为回复一级评论 false为回复二级评论
    private String reply_id = "";
    private String discussion_id = "";
    private AlertDialog showReportAlertView;
    private List<String> strings;
    private int childPosition = -1;
    private String locate_position_id = "";
    private Runnable runnable;
    private Handler handler;
    private int rollPosition = -1;
    private LinearLayoutManager linearLayoutManager;
    private int alpht;
    private AutoRelativeLayout viewByPosition;
    private Runnable runnable1;
    private View viewByPosition1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        setContentView(R.layout.activity_comment_details);
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        locate_position_id = getIntent().getStringExtra(LoongsConfig.locate_position_id);
        if (TextUtils.isEmpty(locate_position_id)) {
            locate_position_id = "";
        }

        initview();
        initdata();
    }

    private void initdata() {
        last_id = "0";
        if (page != 1 && data.size() > 0) {
            last_id = data.get(data.size() - 1).getId();
        }
        OkHttpUtils.get().url(UrlFactory.getDiscussion()).tag(this)
                .addParams(LoongsConfig.user_id, SPUtils.getInstance().getString(LoongsConfig.user_id))
                .addParams(LoongsConfig.reply_id, getIntent().getStringExtra(LoongsConfig.reply_id))
                .addParams(LoongsConfig.locate_position_id, locate_position_id)
                .addParams(LoongsConfig.last_id, last_id)
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                Log.e(TAG, "评论详情onError: " + e.getMessage());
                if (refreshLayout != null) {
                    refreshLayout.finishRefresh();
                    refreshLayout.finishLoadMore();
                }
            }

            @Override
            public void onResponse(String response, int id) {
                refreshLayout.finishRefresh();
                refreshLayout.finishLoadMore();
                Log.e(TAG, "评论详情onResponse: " + response);
                Gson gson = new Gson();
                commentDetailsBean = gson.fromJson(response, CommentDetailsBean.class);
                if (commentDetailsBean.getCode() == 200) {
                    if (page == 1) {
                        if (Util.isOnMainThread() && CommentDetailsActivity.this != null)
                            Glide.with(CommentDetailsActivity.this.getApplicationContext()).load(commentDetailsBean.getData().getUser_portrait_url())
                                    .centerCrop().transform(new CenterCrop(CommentDetailsActivity.this.getApplicationContext()), new GlideCircleTransform(CommentDetailsActivity.this.getApplicationContext()))
                                    .into(userPic);
                        userName.setText(commentDetailsBean.getData().getUser_nickname());
                        commentContext.setText(commentDetailsBean.getData().getText());
                        commentGiveLike.setSelected(commentDetailsBean.getData().getLike_state() == 0 ? false : true);
                        replyNumber.setText("相关回复共" + commentDetailsBean.getData().getDiscussion_amount() + "条");
                        commentTime.setText(TimeUtils.getTimeString(commentDetailsBean.getData().getTime()));
                        likeNumber.setText(commentDetailsBean.getData().getLike_amount() == 0 ? "" : commentDetailsBean.getData().getLike_amount() + "");
                        data.clear();
                    }
                    if (commentDetailsBean.getData() != null && commentDetailsBean.getData().getDiscussion() != null) {
                        data.addAll(commentDetailsBean.getData().getDiscussion());
                        commentDetailsAdapter.notifyDataSetChanged();
                        for (int i = 0; i < data.size(); i++) {
                            if (data.get(i).getId().equals(locate_position_id)) {
                                rollPosition = i;
                            }
                        }
                    }
                }
            }
        });
    }

    private void initview() {
        data = new ArrayList();
        examineForum.setVisibility(View.VISIBLE);
        title.setText("评论详情");
        strings = new ArrayList<>();
        commentDetailsAdapter = new CommentDetailsAdapter(this, data);
        linearLayoutManager = new LinearLayoutManager(this);
        recycler.setLayoutManager(linearLayoutManager);
        recycler.setAdapter(commentDetailsAdapter);
        recycler.setNestedScrollingEnabled(false);
        //设置刷新动画
        refreshLayout.setEnableAutoLoadMore(false);
        refreshLayout.setRefreshHeader(new MaterialHeader(this));

        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                //下拉刷新
                page = 1;
                initdata();
            }
        });
        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(RefreshLayout refreshlayout) {
                //上拉加载
                page++;
                initdata();
            }
        });
        //设置点击事件
        commentDetailsAdapter.setOnClike(new CommentDetailsAdapter.onClikeListener() {
            @Override
            public void onlike(final int position, final ImageView imageView) {
                discussionLike(position, imageView);
            }

            public void comment(final int position) {
                if (!isSoftShowing()) {
                    final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                }
                aBoolean = false;
                discussion_id = data.get(position).getId();
                autoGray.setVisibility(View.VISIBLE);
                reply_id = commentDetailsBean.getData().getId();
                commentEt.setHint("回复@" + data.get(position).getUser_nickname());
            }

            @Override
            public void onReply(final int position1) {
                strings.clear();
                for (String s : CommentDetailsActivity.this.getResources().getStringArray(R.array.forum_comment_report)) {
                    strings.add(s);
                }
                showReportAlertView = AlertViewFactory.getInstance().getShowReportAlertView(CommentDetailsActivity.this, strings, new AlertViewFactory.ReportOnClickListener() {
                    @Override
                    public void submit(final int position) {
                        Log.e(TAG, "submit: " + position);
                        showReportAlertView.cancel();
                        discussionReport(position1, position);
                    }
                });

            }
        });
    }

    /**
     * 举报二级评论
     *
     * @param position
     * @param i
     */
    private void discussionReport(final int position, int i) {
        OkHttpUtils.get().url(UrlFactory.ReportForum())
                .addParams(LoongsConfig.id, data.get(position).getId())
                .addParams(LoongsConfig.user_id, SPUtils.getInstance().getString(LoongsConfig.user_id))
                .addParams(LoongsConfig.type, "2")
                .addParams(LoongsConfig.reason_id, i + 301 + "")
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                Log.e(TAG, "举报评论onError: " + e.getMessage());
            }

            @Override
            public void onResponse(String response, int id) {
                Log.e(TAG, "举报评论response: " + response);
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    int code = jsonObject.getInt(LoongsConfig.code);
                    HintWordsUtils.showMarkeWords(jsonObject.getInt(LoongsConfig.code), jsonObject.getString(LoongsConfig.description));
                    if (code == 200) {
                        ToastUtils.showShort("已提交举报");
                        ForumComment forumComment = new ForumComment(ForumComment.Type.DISCUSSION_REPORT, data.get(position).getId(), getIntent().getIntExtra(LoongsConfig.position, -1));
                        EventBus.getDefault().post(forumComment);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 二级评论点赞
     *
     * @param position
     * @param imageView
     */
    private void discussionLike(final int position, final ImageView imageView) {
        OkHttpUtils.get().url(UrlFactory.getDiscussLike())
                .addParams(LoongsConfig.user_id, SPUtils.getInstance().getString(LoongsConfig.user_id))
                .addParams(LoongsConfig.discussion_id, data.get(position).getId())
                .addParams(LoongsConfig.value, imageView.isSelected() ? "0" : "1")
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                Log.e(TAG, "点击二级点赞 " + e.getMessage());
            }

            @Override
            public void onResponse(String response, int id) {
                Log.e(TAG, "点击二级点赞: " + response);
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    if (jsonObject.getInt(LoongsConfig.code) == 200) {
                        data.get(position).setLike_amount(imageView.isSelected()
                                ? data.get(position).getLike_amount() - 1
                                : data.get(position).getLike_amount() + 1);
                        data.get(position).setLike_state(imageView.isSelected() ? 0 : 1);
                        likeNumber.setText(commentDetailsBean.getData().getLike_amount() == 0 ? "" : commentDetailsBean.getData().getLike_amount() + "");
                        commentDetailsAdapter.notifyDataSetChanged();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
        final int realHeight = metrics.heightPixels;
        handler = new Handler();
        runnable = new Runnable() {
            @Override
            public void run() {
                if (commentDetailsBean != null && rollPosition >= 0) {
                    viewByPosition1 = linearLayoutManager.findViewByPosition(rollPosition);
                    if (viewByPosition1 != null) {
                        //仿微博的颜色渐变
                        alpht = 255;
                        runnable1 = new Runnable() {
                            @Override
                            public void run() {
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        viewByPosition1.setBackgroundColor(Color.argb(alpht, 127, 214, 206));
                                    }
                                });
                                alpht = alpht - 5;
                                if (alpht != 0) {
                                    handler.postDelayed(runnable1, 20);
                                }
                            }
                        };
                        //滚动到相应的位置
                        handler.postDelayed(runnable1, 20);
                        int[] screenLocation = new int[2];
                        int measuredHeight = viewByPosition1.getMeasuredHeight();
                        viewByPosition1.getLocationOnScreen(screenLocation);
                        scrollView.smoothScrollTo(0, screenLocation[1] - realHeight / 2 + measuredHeight / 2);
                        locate_position_id = "";
                    } else {
                        handler.postDelayed(runnable, 100);
                    }
                } else {
                    handler.postDelayed(runnable, 100);
                }
            }
        };
        if (!TextUtils.isEmpty(locate_position_id)) {
            handler.postDelayed(runnable, 200);
        }

    }

    @OnClick({R.id.return_auto, R.id.auto_gray, R.id.comment_et, R.id.issue1, R.id.like_auto, R.id.inform,R.id.examine_forum})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.return_auto:
                finish();
                break;
            case R.id.auto_gray:
                if (isSoftShowing()) {
                    final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                }
                aBoolean = true;
                commentEt.setText("");
                commentEt.setHint("说点什么");
                autoGray.setVisibility(View.GONE);
                break;
            case R.id.comment_et:
                //点击评论框
                if (aBoolean) {
                    aBoolean = true;
                    autoGray.setVisibility(View.VISIBLE);
                    if (commentDetailsBean != null && commentDetailsBean.getData() != null) {
                        reply_id = commentDetailsBean.getData().getId();
                        commentEt.setHint("回复@" + commentDetailsBean.getData().getUser_nickname());
                    }
                }
                break;
            case R.id.issue1:
                //发布评论
                forumIssue();
                break;
            case R.id.like_auto:
                //点赞
                replyLike();
                break;
            case R.id.inform:
                //举报
                strings.clear();
                for (String s : this.getResources().getStringArray(R.array.forum_comment_report)) {
                    strings.add(s);
                }
                showReportAlertView = AlertViewFactory.getInstance().getShowReportAlertView(this, strings, new AlertViewFactory.ReportOnClickListener() {
                    @Override
                    public void submit(final int position) {
                        Log.e(TAG, "submit: " + position);
                        showReportAlertView.cancel();
                        replyInform(position);
                    }
                });
                break;
            case R.id.examine_forum:
                if ("examine_forum".equals(getIntent().getStringExtra(LoongsConfig.type)))
                {
                    Intent intent = new Intent(this, PostDetailsActivity.class);
                    intent.putExtra(LoongsConfig.forum_id, getIntent().getStringExtra(LoongsConfig.forum_id));
                    intent.putExtra(LoongsConfig.name, getIntent().getStringExtra(LoongsConfig.name));
                    intent.putExtra(LoongsConfig.topic, "");
                    startActivity(intent);
                }else
                {
                    finish();
                }
                break;
        }
    }

    /**
     * 一级评论点赞
     */
    private void replyLike() {
        GetBuilder url = OkHttpUtils.get().url(UrlFactory.getReplyLike());
        url.addParams(LoongsConfig.user_id, SPUtils.getInstance().getString(LoongsConfig.user_id))
                .addParams(LoongsConfig.reply_id, getIntent().getStringExtra(LoongsConfig.reply_id))
                .addParams(LoongsConfig.value, commentGiveLike.isSelected() ? "0" : "1")
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                Log.e(TAG, "一级评论点赞onError: " + e.getMessage());
            }

            @Override
            public void onResponse(String response, int id) {
                Log.e(TAG, "一级评论点赞onResponse: " + response);
                JSONObject jsonObject = null;
                try {
                    jsonObject = new JSONObject(response);
                    if (jsonObject.getInt(LoongsConfig.code) == 200) {

                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        });
        commentDetailsBean.getData().setLike_amount(commentGiveLike.isSelected()
                ? commentDetailsBean.getData().getLike_amount() - 1
                : commentDetailsBean.getData().getLike_amount() + 1);
        commentGiveLike.setSelected(!commentGiveLike.isSelected());
        likeNumber.setText(commentDetailsBean.getData().getLike_amount() == 0 ? "" : commentDetailsBean.getData().getLike_amount() + "");
        ForumComment forumComment = new ForumComment(ForumComment.Type.REPLY_LIKE, commentDetailsBean.getData().getId(), getIntent().getIntExtra(LoongsConfig.position, -1));
        forumComment.setLike(commentGiveLike.isSelected());
        EventBus.getDefault().post(forumComment);
    }

    /**
     * 一级评论举报
     *
     * @param position
     */
    private void replyInform(int position) {
        OkHttpUtils.get().url(UrlFactory.ReportForum())
                .addParams(LoongsConfig.id, getIntent().getStringExtra(LoongsConfig.reply_id))
                .addParams(LoongsConfig.user_id, SPUtils.getInstance().getString(LoongsConfig.user_id))
                .addParams(LoongsConfig.type, "1")
                .addParams(LoongsConfig.reason_id, position + 201 + "")
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                Log.e(TAG, "举报评论onError: " + e.getMessage());
            }

            @Override
            public void onResponse(String response, int id) {
                Log.e(TAG, "举报评论response: " + response);
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    HintWordsUtils.showMarkeWords(jsonObject.getInt(LoongsConfig.code), jsonObject.getString(LoongsConfig.description));
                    if (jsonObject.getInt(LoongsConfig.code) == 200) {
                        ToastUtils.showShort("已提交举报");
                        ForumComment forumComment = new ForumComment(ForumComment.Type.REPLY_REPORT, null, getIntent().getIntExtra(LoongsConfig.position, -1));
                        EventBus.getDefault().post(forumComment);
                        finish();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });

    }

    /**
     * 评论详情回复逻辑
     */
    private void forumIssue() {
        if (!TextUtils.isEmpty(commentEt.getText().toString())) {
            if (MyTextUtils.isEmptyString(commentEt)) {
                ToastUtils.showShort("不能发全空格的内容");
                return;
            }
            showLoadingDialog();
            if (aBoolean) {
                ForumComment forumComment = new ForumComment(ForumComment.Type.ADD_DISCUSSION, null, getIntent().getIntExtra(LoongsConfig.position, -1));
                forumComment.setUserID(SPUtils.getInstance().getString(LoongsConfig.user_id));
                forumComment.setCommentContext(commentEt.getText().toString());
                EventBus.getDefault().post(forumComment);
            }
            OkHttpUtils.get().url(aBoolean ? UrlFactory.getDiscussReply() : UrlFactory.getDiscussDiscussion())
                    .addParams(LoongsConfig.user_id, SPUtils.getInstance().getString(LoongsConfig.user_id))
                    .addParams(LoongsConfig.forum_id, getIntent().getStringExtra(LoongsConfig.forum_id))
                    .addParams(LoongsConfig.reply_id, reply_id)
                    .addParams(LoongsConfig.text, commentEt.getText().toString())
                    .addParams(LoongsConfig.discussion_id, aBoolean ? "" : discussion_id)
                    .build().execute(new StringCallback() {
                @Override
                public void onError(Call call, Exception e, int id) {
                    Log.e(TAG, "回复评论: " + e.getMessage());
                    dismissLoadingDialog();
                }

                @Override
                public void onResponse(String response, int id) {
                    Log.e(TAG, "回复评论: " + response);
                    dismissLoadingDialog();
                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        if (jsonObject.getInt(LoongsConfig.code) == 200) {
                            PostDetailsMessageEvent postDetailsMessageEvent = new PostDetailsMessageEvent("2", true);
                            postDetailsMessageEvent.setForumPosition(getIntent().getIntExtra(LoongsConfig.forumPosition, 0));
                            EventBus.getDefault().post(postDetailsMessageEvent);
                            page = 1;
                            initdata();
                            aBoolean = true;
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });
            if (isSoftShowing()) {
                final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
            }
            commentEt.setText("");
            commentEt.setHint("说点什么");
            autoGray.setVisibility(View.GONE);
        }
    }

    private boolean isSoftShowing() {
        //获取当前屏幕内容的高度
        int screenHeight = getWindow().getDecorView().getHeight();
        //获取View可见区域的bottom
        Rect rect = new Rect();
        getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
        return screenHeight - rect.bottom - getSoftButtonsBarHeight() != 0;
    }

    /**
     * 底部虚拟按键栏的高度
     *
     * @return
     */
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    private int getSoftButtonsBarHeight() {
        DisplayMetrics metrics = new DisplayMetrics();
        //这个方法获取可能不是真实屏幕的高度
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        int usableHeight = metrics.heightPixels;
        //获取当前屏幕的真实高度
        getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
        int realHeight = metrics.heightPixels;
        if (realHeight > usableHeight) {
            return realHeight - usableHeight;
        } else {
            return 0;
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void Event(String messageEvent) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    protected String getActivityName() {
        return this.getClass().getSimpleName();
    }

}